package com.gisocn.onemap.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.andrognito.patternlockview.PatternLockView;
import com.andrognito.patternlockview.listener.PatternLockViewListener;
import com.andrognito.patternlockview.utils.PatternLockUtils;
import com.gisocn.onemap.base.BaseActivity;
import com.gisocn.onemap.base.BasePresenter;
import com.gisocn.onemap.model.FingerPassWord;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.utils.SpUtils;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes2.dex */
public class PatternLockActivity extends BaseActivity {
    private FingerPassWord fingerPassWord;
    private String firstPassword;
    private boolean isLogin;
    private LoginActivity mActivity;
    private String password;
    @BindView(R.id.pattern_lock_view)
    PatternLockView patternLockView;
    @BindView(R.id.rl_switch)
    RelativeLayout rlSwitch;
    @BindView(R.id.switch_finger)
    Switch switchFinger;
    @BindView(R.id.tv_input_password)
    TextView tvInputPassword;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_prompt)
    TextView tvPrompt;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private String userId;
    private String userPasswod;
    private int drawCount = 0;
    private ArrayList<String> passwordList = new ArrayList<>();
    private boolean isFirst = true;
    private PatternLockViewListener patternLockViewListener = new PatternLockViewListener() { // from class: com.gisocn.onemap.ui.activity.PatternLockActivity.2
        @Override // com.andrognito.patternlockview.listener.PatternLockViewListener
        public void onStarted() {
        }

        @Override // com.andrognito.patternlockview.listener.PatternLockViewListener
        public void onProgress(List<PatternLockView.Dot> list) {
            String name = getClass().getName();
            Log.d(name, "Pattern progress: " + PatternLockUtils.patternToString(PatternLockActivity.this.patternLockView, list));
        }

        @Override // com.andrognito.patternlockview.listener.PatternLockViewListener
        public void onComplete(List<PatternLockView.Dot> list) {
            String name = getClass().getName();
            Log.d(name, "Pattern complete: " + PatternLockUtils.patternToString(PatternLockActivity.this.patternLockView, list));
            if (PatternLockActivity.this.isLogin) {
                if (PatternLockActivity.this.userPasswod.equals(PatternLockUtils.patternToString(PatternLockActivity.this.patternLockView, list))) {
                    Intent intent = new Intent(PatternLockActivity.this, LoginActivity.class);
                    intent.putExtra("result", true);
                    PatternLockActivity.this.setResult(200, intent);
                    PatternLockActivity.this.finish();
                    return;
                }
                PatternLockActivity.this.tvPrompt.setTextColor(PatternLockActivity.this.getResources().getColor(R.color.colorRed));
                PatternLockActivity.this.tvPrompt.setText("手势密码错误");
                new Thread(new Runnable() { // from class: com.gisocn.onemap.ui.activity.PatternLockActivity.2.2
                    @Override // java.lang.Runnable
                    public void run() {
                        try {
                            PatternLockActivity.this.patternLockView.setFocusable(false);
                            Thread.sleep(1000L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        Message message = new Message();
                        message.arg1 = 1;
                        PatternLockActivity.this.handler.sendMessage(message);
                    }
                }).start();
            } else if (PatternLockUtils.patternToString(PatternLockActivity.this.patternLockView, list).length() >= 6) {
                if (!PatternLockActivity.this.isFirst) {
                    if (PatternLockActivity.this.firstPassword.equals(PatternLockUtils.patternToString(PatternLockActivity.this.patternLockView, list))) {
                        PatternLockActivity patternLockActivity = PatternLockActivity.this;
                        patternLockActivity.password = patternLockActivity.firstPassword;
                        PatternLockActivity.this.fingerPassWord.setPatternLock(true);
                        PatternLockActivity.this.fingerPassWord.setPassWord(PatternLockActivity.this.password);
                        PatternLockActivity.this.fingerPassWord.setEnable(PatternLockActivity.this.switchFinger.isChecked());
                        PatternLockActivity.this.tvPrompt.setText("手势密码设置成功");
                        SpUtils.put(PatternLockActivity.this, "fingerPassWord", new Gson().toJson(PatternLockActivity.this.fingerPassWord));
                        return;
                    }
                    PatternLockActivity.this.tvPrompt.setTextColor(PatternLockActivity.this.getResources().getColor(R.color.colorRed));
                    PatternLockActivity.this.tvPrompt.setText("2次绘制的手势不一致,请重新绘制");
                    new Thread(new Runnable() { // from class: com.gisocn.onemap.ui.activity.PatternLockActivity.2.1
                        @Override // java.lang.Runnable
                        public void run() {
                            try {
                                PatternLockActivity.this.patternLockView.setFocusable(false);
                                Thread.sleep(1000L);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            Message message = new Message();
                            message.arg1 = 0;
                            PatternLockActivity.this.handler.sendMessage(message);
                        }
                    }).start();
                    return;
                }
                PatternLockActivity patternLockActivity2 = PatternLockActivity.this;
                patternLockActivity2.firstPassword = PatternLockUtils.patternToString(patternLockActivity2.patternLockView, list);
                PatternLockActivity.this.tvPrompt.setText("请再次绘制您的登录手势");
                PatternLockActivity patternLockActivity3 = PatternLockActivity.this;
                patternLockActivity3.isFirst = !patternLockActivity3.isFirst;
                PatternLockActivity.this.patternLockView.clearPattern();
            } else {
                PatternLockActivity.this.patternLockView.setWrongStateColor(PatternLockActivity.this.getResources().getColor(R.color.colorRed));
                PatternLockActivity.this.showToast("手势不能少于6个点");
                PatternLockActivity.this.patternLockView.clearPattern();
            }
        }

        @Override // com.andrognito.patternlockview.listener.PatternLockViewListener
        public void onCleared() {
            Log.d(getClass().getName(), "Pattern has been cleared");
        }
    };
    Handler handler = new Handler() { // from class: com.gisocn.onemap.ui.activity.PatternLockActivity.3
        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (message.arg1 == 0) {
                PatternLockActivity.this.patternLockView.clearPattern();
                PatternLockActivity.this.tvPrompt.setTextColor(PatternLockActivity.this.getResources().getColor(R.color.colorBlack));
                PatternLockActivity.this.tvPrompt.setText("请再次绘制您的登录手势");
            } else if (message.arg1 == 1) {
                PatternLockActivity.this.patternLockView.clearPattern();
                PatternLockActivity.this.tvPrompt.setTextColor(PatternLockActivity.this.getResources().getColor(R.color.colorBlack));
                PatternLockActivity.this.tvPrompt.setText("输入手势密码");
            }
            PatternLockActivity.this.patternLockView.setFocusable(true);
        }
    };

    @Override // com.gisocn.onemap.base.BaseActivity
    protected BasePresenter createPresenter() {
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_pattern_lock);
        ButterKnife.bind(this);
        this.patternLockView.addPatternLockListener(this.patternLockViewListener);
        Log.e("手势密码:", "onCreate");
        init();
    }

    void init() {
        boolean booleanExtra = getIntent().getBooleanExtra("isLogin", false);
        this.isLogin = booleanExtra;
        this.rlSwitch.setVisibility(booleanExtra ? 8 : 0);
        if (isNull(SpUtils.get(this, "fingerPassWord", "").toString())) {
            FingerPassWord fingerPassWord = new FingerPassWord();
            this.fingerPassWord = fingerPassWord;
            fingerPassWord.setEnable(false);
            this.fingerPassWord.setPatternLock(false);
        } else {
            this.fingerPassWord = (FingerPassWord) new Gson().fromJson(SpUtils.get(this, "fingerPassWord", "").toString(), (Class<Object>) FingerPassWord.class);
        }
        this.switchFinger.setChecked(this.fingerPassWord.isEnable());
        if (this.isLogin && this.fingerPassWord.isPatternLock() && this.fingerPassWord.isEnable()) {
            this.tvInputPassword.setVisibility(0);
            this.tvTitle.setText("手势登录");
            this.tvPrompt.setText("输入手势密码");
            this.userPasswod = this.fingerPassWord.getPassWord();
            if (!isNull(getIntent().getStringExtra("userName"))) {
                this.tvName.setVisibility(0);
                this.tvName.setText(getIntent().getStringExtra("userName"));
            }
            Log.e("手势密码:", this.userPasswod);
        } else {
            this.tvInputPassword.setVisibility(8);
            this.tvTitle.setText("手势设置");
        }
        this.switchFinger.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // from class: com.gisocn.onemap.ui.activity.PatternLockActivity.1
            @Override // android.widget.CompoundButton.OnCheckedChangeListener
            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                PatternLockActivity.this.fingerPassWord.setEnable(z);
                SpUtils.put(PatternLockActivity.this, "fingerPassWord", new Gson().toJson(PatternLockActivity.this.fingerPassWord));
            }
        });
    }

    @OnClick({R.id.tv_close, R.id.tv_input_password})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.tv_close) {
            finish();
        } else if (id != R.id.tv_input_password) {
        } else {
            finish();
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        Log.e("PatternLock", "onDestroy");
    }
}
